<template>
  <div class="app-container">
    <el-button @click="dialogFormVisible=true">添加套餐</el-button>
    <el-dialog title="添加套餐" :visible.sync="dialogFormVisible">
      <el-form>
        <el-form-item label="套餐名">
          <el-input v-model="pck.name" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="套餐价格" >
          <el-input  v-model="pck.price" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="套餐时间" >
          <el-input  v-model="pck.timenum" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="套餐时间单位" >
            <el-radio v-model="pck.timeunit" label="月">月</el-radio>
            <el-radio v-model="pck.timeunit" label="季度">季度</el-radio>
            <el-radio v-model="pck.timeunit" label="年">年</el-radio>
        </el-form-item>
        <!-- <el-form-item label="套餐价格" >
          <el-input  v-model="pck.price" autocomplete="off"></el-input>
        </el-form-item> -->
        <el-form-item label="套餐备注">
          <el-input v-model="pck.remark" autocomplete="off" type="textarea"></el-input>
        </el-form-item>


        <el-form-item label="套餐权限" >
          <el-checkbox-group v-model="pck.permIds">
                <el-checkbox v-for="(item,index) in permList" :key="index" :label="item.id" :value="item.id">{{ item.permName }}</el-checkbox>
          </el-checkbox-group>
        </el-form-item>

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="adds()">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import {fetchAllPerms,add} from '@/api/pck';
export default {
  data() {
    return {
      dialogFormVisible: false,
      pck: {
        permIds:[]
      },
      permList:[],
      // permsid:[]
    
    };
  },
  methods:{
    adds(){
        this.pck.permIds=JSON.stringify(this.pck.permIds);
        add(this.pck).then(res=>{
            this.$message({
                type:res.ok?'success':'error',
                msg:res.message

            });
            this.dialogFormVisible=false;
    })    
    }   
  },
  
  created() {
    //获取所有的权限列表
    fetchAllPerms().then(res=>{
       this.permList= res.data
    })
  },
};
</script>
<style lang="css">
</style>